﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

/// <reference name="MicrosoftAjax.js" />

Type.registerNamespace("Microsoft.Live.ClientControls.VE.Extenders") ; 
Microsoft.Live.ClientControls.VE.Extenders.Traffic = function(element) {
    /// <summary>
    ///   The Microsoft Live Server Controls VE Map Traffic Extender client side code.
    /// </summary>
    /// <param name="element">The DOM element to have Traffic event on click.</param>
    Microsoft.Live.ClientControls.VE.Extenders.Traffic.initializeBase(this, [element]) ; 
    this._toggleTraffic;
    this._toggleTrafficLegend;
    this._showTraffic;
    this._showTrafficLegend;
    this._hideTraffic;
    this._hideTrafficLegend;
    this._trafficLegendText;
    this._mapControlID;
} 

Microsoft.Live.ClientControls.VE.Extenders.Traffic.prototype = {

    initialize : function() {
        /// <summary>
        ///   Initialises the Extender.
        /// </summary>       
        Microsoft.Live.ClientControls.VE.Extenders.Traffic.callBaseMethod(this, 'initialize');
        
        $addHandler(this.get_element(),"click", Function.createDelegate(this, this._onClick));
    },
    
    get_ToggleTraffic : function() {
        return this._toggleTraffic;
    }, 

    set_ToggleTraffic : function(value) {
        this._toggleTraffic = value;
    },   
         
       
    get_ToggleTrafficLegend : function() {
        return this._toggleTrafficLegend;
    }, 

    set_ToggleTrafficLegend : function(value) {
        this._toggleTrafficLegend = value;
    },        
    
    get_ShowTraffic : function() {
        return this._showTraffic;
    }, 

    set_ShowTraffic : function(value) {
        this._showTraffic = value;
    },  
    
    get_ShowTrafficLegend : function() {
        return this._showTrafficLegend;
    }, 

    set_ShowTrafficLegend : function(value) {
        this._showTrafficLegend = value;
    },        
    
    get_HideTraffic : function() {
        return this._hideTraffic;
    }, 

    set_HideTraffic : function(value) {
        this._hideTraffic = value;
    }, 
    
    get_HideTrafficLegend : function() {
        return this._hideTrafficLegend;
    }, 

    set_HideTrafficLegend : function(value) {
        this._hideTrafficLegend = value;
    },        
    
    get_TrafficLegendText : function() {
        return this._trafficLegendText;
    }, 
  
    set_TrafficLegendText : function(value) {
        this._trafficLegendText = value;
    },        
     
    get_MapControlID : function() {
        return this._mapControlID;
    }, 

    set_MapControlID : function(value) {
        this._mapControlID = value;
    },        
    
    _onClick : function(e) {
        //Get the map control and Traffic
        var mapcontrol = $find(this._mapControlID);
        if (mapcontrol) {
            if (this._toggleTraffic) {
                mapcontrol.set_Traffic(!mapcontrol.get_Traffic());
            }
            if (this._toggleTrafficLegend) {
                mapcontrol.set_TrafficLegend(!mapcontrol.get_TrafficLegend());
            }
            if (this._showTraffic) {
                mapcontrol.set_Traffic(true);
            }
            if (this._hideTraffic) {
                mapcontrol.set_Traffic(false);
            }
            if (this._showTrafficLegend) {
                mapcontrol.set_TrafficLegend(true);
            }
            if (this._hideTrafficLegend) {
                mapcontrol.set_TrafficLegend(false);
            }
            if (this._trafficLegendText != "") {
                mapcontrol.set_TrafficLegendText(this._trafficLegendText);
            }
        }
        //Don't want the page to post back, so prevent default action of control
        e.preventDefault();
    },
    
    dispose : function() {
        /// <summary>
        ///   Dispose all events and objects.
        /// </summary>     
        $clearHandlers(this.get_element());
        Microsoft.Live.ClientControls.VE.Extenders.Traffic.callBaseMethod(this, 'dispose');
    }
} 

Microsoft.Live.ClientControls.VE.Extenders.Traffic.registerClass("Microsoft.Live.ClientControls.VE.Extenders.Traffic", Sys.UI.Behavior) ;

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();